package de.barny.swing;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.Toolkit;

import javax.swing.JComponent;

public class SkewLabel extends JComponent {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	double radians;
	String text;
	int stringHeight = Toolkit.getDefaultToolkit().getScreenSize().height/10;
	double scaleX;
	double scaleY;
	
	SkewLabel (double d, String t, double sX, double sY) {
		radians = d;
		text = t;
		scaleX = sX;
		scaleY = sY;
	}
	
	@Override
	protected void paintComponent(Graphics skewLabelGraphics) {
		super.paintComponent(skewLabelGraphics);
		Graphics2D l = (Graphics2D)skewLabelGraphics;
		l.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
		
		l.setColor(new Color(240, 250, 240));
		l.setFont(new Font("ARIAL", Font.BOLD, stringHeight));
		int height = (int) ((Math.sin(Math.abs(radians)) * l.getFontMetrics().stringWidth(text) + stringHeight));
		int width = (int) ((Math.cos(Math.abs(radians)) * l.getFontMetrics().stringWidth(text) + stringHeight));
		l.translate(scaleX*stringHeight, scaleY*height);
		l.scale(scaleX, scaleY);
		l.rotate(radians);
		l.drawString(text, 0, 0);
		setSize((int) (scaleX*width), Toolkit.getDefaultToolkit().getScreenSize().height);
	}
	
}
